
import Common from "../../Common/Common";

export default class SignIn extends Laya.Dialog{
    [x: string]: any;

	constructor(){
		super();
    }
    
    onOpened(){
        //Laya.timer.once(20,this,this.initData);
        //this.btnEvent();
        this.updateBtn();
    }

    /**初始化场景数据 */
    initData(){
        //let Data=Dataa.UserData;
        
        

    }

    /**按键监听事件 */
    btnEvent(){   
        
        //点击后的动作
        //this.collectBtn.on(Laya.Event.CLICK,this,this.action,["collect"]);
        
        
        
    }

    updateBtn(){
        let lastIndex = 0;
        //是否已经签到
        for (let index = 1; index < 10; index++) {
            let sign = Common.getCacheItem("day"+index+"SignIn");
            if(sign != null && sign == "1"){
                this.getChildByName("day"+index).visible = true
                console.log(index)
                lastIndex = index
            }else{
                console.log(index)
                this.SignInButn.once(Laya.Event.CLICK,this,this.sign,[index]);
                break
            }
            
        }

        if(lastIndex == 9){//第9天已签到时清空
            for (let index = 1; index < 10; index++) {
                let singnType = this.getChildByName("day"+index)
                Common.setCacheItem("day"+index+"SignIn","0");
                singnType.visible = false    
            }
            lastIndex = 0;
        }
    }
    /**
     * 签到
     */
    sign(index){
        Laya.stage.event("playSound",["sound/tap.mp3"])
        let singnType = this.getChildByName("day"+index)
        let lastSignDate = Common.getCacheItem("signDate");
        // if(lastSignDate == Common.getNowDate()){
        //     Laya.stage.event("ShowMsg","今天已经签到了!");
        //     return;
        // }
        // Laya.stage.event("ShowMsg","签到成功!");
        
        singnType.visible = true;
        Common.setCacheItem("signDate",Common.getNowDate());
        Common.setCacheItem("day"+index+"SignIn","1");
        this.close()
        Laya.Scene.open("Dialog/Receive.scene",false,{type:"singin",index:index})
    }

    



}